<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<script>
var sources = new Array()
sources[0] = "owner"
sources[1] = "discuz"
sources[2] = "phpwind"
sources[3] = "wordpress"
sources[4] = "connector"
sources[5] = "smtp"
sources[6] = "ldap"

var Show = {};

Show.Show = {
	execute : function(source) {
		for (i=0;i<sources.length;i++)
	    {
			$("#source_"+sources[i]).hide();
	    }
    	$("#source_"+source).show(1000);
    }
}


Show.Radio = {
    click : function(obj) {
    	Show.Show.execute(obj.value);
    }
}
    

$(document).ready(function () {
	Show.Show.execute("<?php echo $userDbSource?>");
});


</script>



<?php $this->pageTitle="用户源设置"; ?>
<div class="icon32" id="icon-users"><br>
</div>
<h2>用户源设置<span class="description">(可兼容discuz、phpWind、wordpress与接口用户源[不可同时开启],也可以自定义注册, 以及找回密码地址</span>
</h2>


<?php
$sourceList = Array(
                   "owner"=>"不使用第三方源",
                   "discuz"=>"discuz",
                   "phpwind"=>"phpwind",
                   "wordpress"=>"wordpress", 
                   "smtp"=>"兼容smtp协议",
                   "ldap"=>"ldap服务",
				   "connector"=>"简单接口",);

$sourceDes  = Array(
	"owner"=>"使用自有的用户体系",
	"discuz"=>"使用discuz用户体系",
	"phpwind"=>"使用phpwind用户体系",
	"wordpress"=>"使用wordpress用户体系",
	"connector"=>"简单接口方式的用户体系",
	"smtp"=>"兼容smtp用户体系",
    "ldap"=>"使用ldap用户体系"
);


$sourceDescription = Array(
	"owner"=>"使用自有的用户体系",
	"discuz"=>"测试通过Discuz_X2及以上版本",
	"phpwind"=>"测试通过phpwind_8.7及以上版本",
	"wordpress"=>"测试通过WordPress 3.2.1及以上版本",
	"connector"=>"快速实现用户体系的对接",
	"smtp"=>"兼容smtp用户体系",
    "ldap"=>"使用ldap用户体系"
);


$detailUrl = Array(
	"owner"=>"使用自有的用户体系",
	"discuz"=>"http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=161",
	"phpwind"=>"http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=163",
	"wordpress"=>"http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=162",
	"connector"=>"http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=166",
	"smtp"=>"http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=165",
    "ldap"=>"http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=164"
);

?>

<?php if ($success == 1) {?>
    <div class="updated" id="message"><p>更新成功。</p></div>
<?php }?>



<h2 class="nav-tab-wrapper">
    <a class="nav-tab nav-tab-active" href="<?php echo(Yii::app()->params['app']['host'])?>/index.php?r=adminSettingPanel/user">管理用户源</a>
    <a class="nav-tab" href="<?php echo(Yii::app()->params['app']['host'])?>/index.php?r=adminSettingPanel/url">管理地址</a>
</h2>


<h3>用户源选择</h3>
<table class="form-table" style="line-height: 10px;">
    <tbody>
    <?php foreach($sourceList as $key=>$value){ ?>
        <tr>
            <th><label><input onclick="Show.Radio.click(this)" <?php echo $key==$userDbSource?"checked":""?> type="radio" name="db_source" value="<?php echo $key?>"><?php echo $value?><?php echo $key==$currentUserDbSource?"(当前使用)":""?></label></th>
            <td><code><?php echo $sourceDes[$key]?></code></td>
        </tr>
    <?php } ?>
</tbody></table>


<?php 
$source =array("三"=>array("discuz","discuz"),
           "四"=>array("phpwind","phpwind"),
           "五"=>array("wordpress","wordpress"),
);

$registerData  = $registerModel->getData();
?>


<br><br>
<h3>填写基本信息</h3>
<p>请正确填写第三方用户源信息，填写正确后，用户的身份验证将不使用自有系统,而是根据您填写的信息进行用户身份验证</p>
<p><font color="red">提示：</font>用户名  admin 为系统保留账户，不能使用admin验证第三方用户源</p>

<table class="form-table" id="source_owner">
	<tr class="form-field form-required">
		<th scope="row" style="width: 200px;"><label for="adapter_discuz">#使用自己的用户源<span
			class="description">(迷你云验证通过自有的用户系统)</span></label></th>
		<td></td>
	</tr>
	<form action="<?php echo(Yii::app()->params['app']['host'])?>/index.php?r=adminSettingPanel/user" method="post">
    <input type="hidden" name="userSource" value="owner">
	<tr class="form-field form-required">
		<td scope="row" style="width: 50px;">
		<div><label>使用此用户源</label> </div>
		</td>
	</tr>
	<tr class="form-field form-required">
		<td>
		<div
			style="background: #fff; color: #333; font-family: sans-serif; margin: 2em auto; width: 500px; padding: 1em 2em; -moz-border-radius: 11px; -khtml-border-radius: 11px; -webkit-border-radius: 11px; border-radius: 11px; border: 1px solid #dfdfdf;">
		<p class="step" style="width: 100px"><input name="submit"
			type="submit" value="提交" class="button-primary" /></p>
		</div>
		</td>
	</tr>
	</form>
</table>



<?php foreach($source as $number=>$valueSource){ ?>
<table class="form-table" id="source_<?php echo $valueSource[0]?>">
	<tr class="form-field form-required">
		<th scope="row" style="width: 200px;"><label for="adapter_discuz">#兼容<?php echo $valueSource[1] ?>用户源<span class="description">
            (<?php echo  $sourceDescription[$valueSource[1]]?>)
            </span></label></th>
		<td></td>
	</tr>
	<?php $form=$this->beginWidget('CActiveForm'); ?>
    <input type="hidden" name="userSource" value="<?php echo $valueSource[1] ?>">
	<tr class="form-field form-required">
		<td scope="row" style="width: 50px;">
		<div><label>使用此用户源  </label><a target="_blank" href="<?php echo $detailUrl[$valueSource[0]]?>"> 详细说明</a></div>
		</td>
	</tr>
	<tr class="form-field form-required">
		<td>
		<div style="background: #fff; color: #333; font-family: sans-serif; margin: 2em auto; width: 500px; padding: 1em 2em; -moz-border-radius: 11px; -khtml-border-radius: 11px; -webkit-border-radius: 11px; border-radius: 11px; border: 1px solid #dfdfdf;">
		<table class="form-table">
		<?php foreach($model->getDataSource($valueSource[0]) as $key=>$value){ ?>
			<tr>
				<th scope="row"><label for="dbname"><?php echo $value[0]?></label></th>
				
				<?php 
				if ($key == $valueSource[1]."DbAddress"){
				    if (empty($value[1])){
				        $value = "127.0.0.1";
				    } else { 
				        $value = $value[1];
				    }
				    $textfieldArray = array('size'=>25, 'value'=>$value);
				} else if ($key == $valueSource[1]."TablePrefix"){
				    if (empty($value[1])){
				        if ($valueSource[1]=="discuz"){
				            $value = "pre_";
				        } elseif ($valueSource[1]=="phpwind"){
				            $value = "pw_";
				        } elseif ($valueSource[1]=="wordpress"){
				            $value = "wp_";
				        } else {
				            $value = $value[1];
				        }
				    } else { 
				        $value = $value[1];
				    }
				    $textfieldArray = array('size'=>25, 'value'=>$value);
				} else {
				    $textfieldArray = array('size'=>25, 'value'=>$value[1]);
				}
				?>

				<td><?php echo $form->textField($model, $key, $textfieldArray); ?></td>
				<?php echo $form->error($model, $key); ?>
			</tr>
			<?php }?>
		</table>
		<p class="step" style="width: 100px"><input name="submit"
			type="submit" value="提交并验证" class="button-primary" /></p>
		</div>
		</td>
	</tr>
</table>
<?php $this->endWidget(); ?>
<?php } ?>



<table class="form-table" id="source_connector">
	<tr class="form-field form-required">
		<th scope="row"><label for="adapter_discuz">#简单接口 <span class="description">(<?php echo  $sourceDescription['connector']?>)</span></label></th>
	</tr>
	
	<?php $form=$this->beginWidget('CActiveForm'); ?>
	<input type="hidden" name="userSource" value="connector">
    <tr class="form-field form-required">
        <td scope="row" style="width: 50px;">
        <div><label>使用此用户源  </label><a target="_blank" href="<?php echo $detailUrl["connector"]?>"> 详细说明</a></div>
        </td>
    </tr>
	<tr class="form-field form-required" style="float:left">
		<td>
		<div style="background: #fff; color: #333; font-family: sans-serif; margin: 2em auto; width: 500px; padding: 1em 2em; -moz-border-radius: 11px; -khtml-border-radius: 11px; -webkit-border-radius: 11px; border-radius: 11px; border: 1px solid #dfdfdf;">
		<table class="form-table">
		<?php foreach($modelconnector->getData() as $key=>$value){ ?>
			<tr>
				<th scope="row"><label for="api_url">接口地址</label></th>
                <?php if ($userDbSource == "connector"){
                    $textfieldArray = array('size'=>25, 'value'=>$value[1]);
                }else{
                    $textfieldArray = array('size'=>25, 'value'=>$value[1]);
                }?>
				<td><?php echo $form->textField($modelconnector, $key, $textfieldArray); ?></td>
			</tr>
			<tr>
				<th scope="row"><label for="api_url">接口说明</label></th>
				<td>
				<div class="dp-highlighter">输入:http://www.abc.com/users/?name=xiaoming&password=123456<br>
				通过返回值：{success:true,'nick':"张三"}<br>
				否则返回值：{success:false,msg:"错误"}</div>
				</td>
			</tr>
			<?php echo $form->error($modelconnector, $key); ?>
		<?php }?>
		</table>
		<p class="step" style="width: 100px"><input name="submit" type="submit" value="提交并验证"
			class="button-primary" /></p>
		
		</div>
		</td>
	</tr>
	<?php $this->endWidget(); ?>
</table>


<table class="form-table" id="source_smtp">
    <tr class="form-field form-required">
        <th scope="row" style="width: 200px;"><label for="adapter_smtp">#兼容使用smtp方式登录</br>
                             主流smtp服务      :<span class="description">  (支持qq,163,sina,sohu等各主流邮件服务登录)</span><br>
                             自定义smtp服务 :<span class="description">  (只提供自己所使用的邮件服务登录)</span>
         </label></th>
        <td></td>
    </tr>
    <tr class="form-field form-required">
        <td scope="row" style="width: 50px;">
        <div><label>使用此用户源  </label> <a target="_blank" href="<?php echo $detailUrl["smtp"]?>"> 详细说明</a></div>
        </td>
    </tr>
    <tr class="form-field form-required">
        <td>
        <div style="background: #fff; color: #333; font-family: sans-serif; margin: 2em auto; width: 500px; padding: 1em 2em; -moz-border-radius: 11px; -khtml-border-radius: 11px; -webkit-border-radius: 11px; border-radius: 11px; border: 1px solid #dfdfdf;">
        <form action="<?php echo(Yii::app()->params['app']['host'])?>/index.php?r=adminSettingPanel/user" method="post">
        <input type="hidden" name="userSource" value="smtp">
        <table class="form-table" id="source_smtp">
            <?php echo $form->errorSummary($smtpModel,""); ?>
            <tbody>
            <tr valign="top">
                <th scope="row" style="width: 100px;">smtp设置</th>
                <td id="front-static-pages"><fieldset><legend class="screen-reader-text"><span>首页显示</span></legend>
                    <p><label>
                        <?php ?>
                        <input type="radio" id="SmtpViewForm_smtpType" name="SmtpViewForm[smtpType]" onclick="$('#smtpServerInput,#smtpPortInput,#smtpSecureInput').attr('disabled',true);" <?php echo ($smtpModel->getSmtpType()=="all")?"checked='checked'":""?> style="width: 20px;border:none;" class="tog" value="all">                                    
                                                                主流smtp服务  </label>
                    </p>
                    <p><label>
                        <?php ?>
                        <input type="radio" id="SmtpViewForm_smtpType" name="SmtpViewForm[smtpType]" onclick="$('#smtpServerInput,#smtpPortInput,#smtpSecureInput').attr('disabled',false);" <?php echo ($smtpModel->getSmtpType()=="custom")?"checked='checked'":""?> style="width: 20px;border:none;" class="tog" value="custom">                                         
                                                                 自定义smtp服务（在下方填写） </label>
                    </p>
                <ul>
                    <li><label for="page_on_front">服务地址 <span class="description"> 示例：smtp.qq.com </span></label>
                        <?php ?>
                        <input type="text" name="SmtpViewForm[smtpServer]" <?php echo ($smtpModel->getSmtpType()=="custom")?"":"disabled"?> value="<?php echo $smtpModel->getSmtpServer();?>" id="smtpServerInput">
                    </li>
                    <li><label for="page_on_front">端口 <span class="description"> 默认 25 </span></label>
                        <input type="text" name="SmtpViewForm[smtpPort]" <?php echo ($smtpModel->getSmtpType()=="custom")?"":"disabled"?> value="<?php echo $smtpModel->getSmtpPort();?>" id="smtpPortInput">
                    </li>
                    <li>
                        <label for="page_on_front">使用安全协议 <span class="description"> </span></label><br>
                        <select name="SmtpViewForm[smtpSecure]" <?php echo ($smtpModel->getSmtpType()=="custom")?"":"disabled"?> value="<?php echo $smtpModel->getSmtpPort();?>" id="smtpSecureInput">
                            <option value="" <?php echo ($smtpModel->getSmtpSecure()=="")?"selected='selected'":""?>>无协议</option>
                            <option value="ssl" <?php echo ($smtpModel->getSmtpSecure()=="ssl")?"selected='selected'":""?>>SSL</option>
                            <option value="TLS" <?php echo ($smtpModel->getSmtpSecure()=="tls")?"selected='selected'":""?>>TLS</option>
                        </select>
                    </li>
                </ul>
                </fieldset></td>
                </tr>
            <tr><th scope="row"><p class="step" style="width: 100px"><input name="submit" type="submit" value="提交" class="button-primary" /></p></th></tr>
           </tbody>
         </table>
        </form>
        </div>
        </td>
    </tr>
</table>


<table class="form-table" id="source_ldap">
	<tr class="form-field form-required">
		<th scope="row" style="width: 200px;"><label for="adapter_discuz">#兼容ldap用户源</br>
        <span class="description">配置自己的ldap服务地址，端口，以及基本DN</br>
                      服务地址：       ldap://xxxx</br>
                      服务端口：      389</br>
                      基本DN:     dc=xx,dc=xx</br>
                      注意： 如果使用ldap服务，需要配置php.ini, extension=php_ldap.dll extension=php_gettext.dll需要去掉注释
            </span></label></th>
		<td></td>
	</tr>
	<?php $form=$this->beginWidget('CActiveForm'); ?>
    <input type="hidden" name="userSource" value="ldap">
	<tr class="form-field form-required">
		<td scope="row" style="width: 50px;">
		<div><label>使用此用户源   </label><a target="_blank" href="<?php echo $detailUrl["ldap"]?>"> 详细说明</a></div>
		</td>
	</tr>
	<tr class="form-field form-required">
		<td>
		<div style="background: #fff; color: #333; font-family: sans-serif; margin: 2em auto; width: 500px; padding: 1em 2em; -moz-border-radius: 11px; -khtml-border-radius: 11px; -webkit-border-radius: 11px; border-radius: 11px; border: 1px solid #dfdfdf;">
		<table class="form-table">
		<?php echo $form->errorSummary($ldapModel,""); ?>
			<tr>
				<th scope="row"><label for="dbname">ldap服务地址</label></th>
				<td><?php echo $form->textField($ldapModel, "ldapHost", array("value"=>$ldapModel->getLdapHost())); ?></td>
			</tr>
			<tr>
				<th scope="row"><label for="dbname">ldap服务端口</label></th>
				<td><?php echo $form->textField($ldapModel, "ldapPort", array("value"=>$ldapModel->getLdapPort())); ?></td>
			</tr>
			<tr>
				<th scope="row"><label for="dbname">ldap服务基本DN</label></th>
				<td><?php echo $form->textField($ldapModel, "ldapBaseCn", array("value"=>$ldapModel->getLdapBaseCn())); ?></td>
			</tr>
		</table>
		<p class="step" style="width: 100px"><input name="submit"
			type="submit" value="提交并验证" class="button-primary" /></p>
		</div>
		</td>
	</tr>
</table>
<?php $this->endWidget(); ?>




<style>

.errorMessage {
    background: none repeat scroll 0 0 #FFEEEE;
    color: red;
    font-size: 0.9em;
}


.errorSummary {
    color: red;
    background: none repeat scroll 0 0 #FFEEEE;
    border: 0px solid #CC0000;
    font-size: 0.9em;
    margin: 0 0 20px;
    padding: 0px;
}

</style>